/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import model.User;

/**
 *
 * @author Rima
 */
public class databaseReg extends DBClass {
    private String sql;
    private Connection con;
    private Statement stmt;
    private ResultSet rs;
    
////      public List getAllRegister() throws SQLException, ClassNotFoundException{
////          sql = "SELECT * FROM `admin`";
////          return getRegister;
////      }
////      
////      private List get

      public int reg(User bb) throws ClassNotFoundException, SQLException {
        try {
        User dataUser = new User();
        Connection con = buatKoneksi();
        PreparedStatement st = con.prepareStatement("INSERT INTO admin (`nama`,`email`,`Ruang_id_ruang`,`password`)VALUES (?,?,?,?)");
             st.setString(1, bb.getNama());
             st.setString(2, bb.getEmail());
             st.setInt(3, bb.getId_ruang());
             st.setString(4, bb.getPassword());
            
            int i = st.executeUpdate();
            System.out.println("testing");
            return i;
          
     }  catch (ClassNotFoundException | SQLException e) {
         System.out.println(e);
            return 0;
    }
    }
      public List getAlldetails() throws SQLException, ClassNotFoundException {

        Connection con = buatKoneksi();
        PreparedStatement st = con.prepareStatement("select * from admin");
        ResultSet rs = st.executeQuery();
        List list = new ArrayList();
        while (rs.next()) {
            User ubean = new User();
            ubean.setNama(rs.getString(2));
            ubean.setEmail(rs.getString(3));
            ubean.setId_ruang(5);
            ubean.setPassword(rs.getString(6));
            
            list.add(ubean);

        }
        return list;
    }
}
